<?php
namespace app\np\command;

use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\console\input\Argument;
use think\Db;
use think\Config;

/**
 * Class Automatic
 * @package app\np\command 自动行权
 */
class Automatic extends Command
{
    protected function configure()
    {
        $this->setName('autc')->setDescription('cover every Minutes ');

    }
    protected function execute(Input $input, Output $output)
    {

       //每分钟执行平仓
        $v_time =60*60*8;
        $c_time = time();

        //订单流操作
        $OrderDetailsModel= new \app\np\model\OrderDetails();//订单详情 前台订单卖出操作
        $OrderDetailsModelResult = $OrderDetailsModel
            ->alias("a")
            ->field("a.*,s.code,c.key")
            ->join("shares s","a.stock_id = s.id","left")
            ->join("configs c","c.id = s.attribute","left")
            ->where("a.status",2)
            ->limit(5)
            ->order("a.money_expiry_date asc")->limit(5)->select();
        if(!empty($OrderDetailsModelResult)){
            $OrderDetailsModelResult = json_decode(json_encode($OrderDetailsModelResult),true);
            foreach($OrderDetailsModelResult as $k=>$v){
                                if(!empty($v['money_expiry_date'])){
                                    $money_expiry_date = bcadd($v['money_expiry_date'],$v_time);
                                    if($c_time>$money_expiry_date){ //行权到期日
                                        $Profit =   getYhAttrComm(1,$v);
                                        if(!$Profit){
                $data = ["direction"=>0,"is_sell_status"=>3,"status"=>3,"exercise_price"=>0,"sell_money"=>0,"sell_time"=>time()];
                                            $OrderDetailsModel->save($data,['id'=>$v['id']]);
                                        }

                                    }

                                }

            }

        }








    }
}